﻿package com.scn.base.util;

import java.util.Vector;
import com.scn.base.page.TreeNode;
/**
 * 生成用户菜单    
 * @author GX       
 * @version 1.0     
 * @created Apr 20, 2011 3:42:18 AM
 */
public class FuncUtil {
	public static String getMenu(TreeNode root){
		StringBuffer sb=new StringBuffer();
		sb.append("document.write('<ul id=MenuUl>');").append("\r\n");
		Vector<TreeNode> first=root.getAllChild();
		for(TreeNode n:first){
			if(n.hasChild()){//第一级菜单
				sb.append("document.write('  <li class=level1><div class=level1Style id=MEMU_FUNC"+n.getId()+" onclick=menuClick(this);><img class=Icon src=\"'+basename+'"+n.getImg()+"\"> "+n.getName()+"</div>');").append("\r\n");
				sb.append("document.write('    <ul class=MenuLevel2 id=MEMU_FUNC"+n.getId()+"d style=\"DISPLAY: none\">');").append("\r\n");
				Vector<TreeNode> second=n.getAllChild();
				for(TreeNode p:second){//第二级菜单
					if(p.hasChild()){
						sb.append("document.write('      <li class=level2><div class=level2Style id=MEMU_FUNC"+p.getId()+" onclick=subMenuClick(this);><img id=MEMU_FUNC"+p.getId()+"_img src=\"'+basename+'/gximages/style1/menu/menu_arrow_close.gif\"> "+p.getName()+"</div>');").append("\r\n");
						sb.append("document.write('        <ul class=MenuLevel2 id=MEMU_FUNC"+p.getId()+"d style=\"DISPLAY: none\">');").append("\r\n");
						Vector<TreeNode> third=p.getAllChild();
						for(TreeNode q:third){//第三级菜单
							sb.append("document.write('          <li  id=MEMU_FUNC"+q.getId()+" onclick=\\'actionPageUrl(\"'+basename+'"+q.getLink()+"\");\\' class=level3Head>"+q.getName()+"</li>');").append("\r\n");
						}
						sb.append("document.write('        </ul>');").append("\r\n");
						sb.append("document.write('      </li>');").append("\r\n");
					}else{
						sb.append("document.write('      <li class=level2><div class=level2Style id=MEMU_FUNC"+p.getId()+" onclick=\\'actionPageUrl(\"'+basename+'"+p.getLink()+"\");\\'><img id=MEMU_FUNC"+p.getId()+"_img src=\"'+basename+'/gximages/style1/menu/menu_arrow_single.gif\"> "+p.getName()+"</div>');").append("\r\n");
					}
				}
				sb.append("document.write('    </ul>');").append("\r\n");
				sb.append("document.write('  </li>');").append("\r\n");
			}
		}
		sb.append("document.write('</ul>');");
		return sb.toString();
	}
}
